package com.ruoyi.official.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.official.domain.Receive;
import com.ruoyi.personnel.domain.Department;
import com.ruoyi.personnel.domain.Employee;
import com.ruoyi.personnel.mapper.DepartmentMapper;
import com.ruoyi.personnel.mapper.EmployeeMapper;
import com.ruoyi.tools.domain.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.official.mapper.MoneyMapper;
import com.ruoyi.official.domain.Money;
import com.ruoyi.official.service.IMoneyService;

/**
 * 财务用款管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-07
 */
@Service
public class MoneyServiceImpl implements IMoneyService 
{
    @Autowired
    private MoneyMapper moneyMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    private DepartmentMapper departmentMapper;
    /**
     * 查询财务用款管理
     * 
     * @param spendMoneyId 财务用款管理主键
     * @return 财务用款管理
     */
    @Override
    public Money selectMoneyBySpendMoneyId(Integer spendMoneyId)
    {
        return moneyMapper.selectMoneyBySpendMoneyId(spendMoneyId);
    }

    /**
     * 查询财务用款管理列表
     * 
     * @param money 财务用款管理
     * @return 财务用款管理
     */
    @Override
    public List<Money> selectMoneyList(Money money)
    {
        List<Money> monies = moneyMapper.selectMoneyList(money);
        for (Money money1 : monies) {
            Department department = departmentMapper.selectDepartmentByDepId(money1.getDepId());
            money1.setDepName(department.getDepName());
            Employee employee = employeeMapper.selectEmployeeByEmpId(money1.getEmpId());
            money1.setEmpName(employee.getEmpName());
        }
        return monies;

    }

    /**
     * 新增财务用款管理
     * 
     * @param money 财务用款管理
     * @return 结果
     */
    @Override
    public int insertMoney(Money money)
    {
        money.setCreateTime(DateUtils.getNowDate());
        money.setVersion(0);
        money.setState(0);
        return moneyMapper.insertMoney(money);
    }

    /**
     * 修改财务用款管理
     * 
     * @param money 财务用款管理
     * @return 结果
     */
    @Override
    public int updateMoney(Money money)
    {

        money.setUpdateTime(DateUtils.getNowDate());
        return moneyMapper.updateMoney(money);
    }

    /**
     * 批量删除财务用款管理
     * 
     * @param spendMoneyIds 需要删除的财务用款管理主键
     * @return 结果
     */
    @Override
    public int deleteMoneyBySpendMoneyIds(Integer[] spendMoneyIds)
    {
        return moneyMapper.deleteMoneyBySpendMoneyIds(spendMoneyIds);
    }

    /**
     * 删除财务用款管理信息
     * 
     * @param spendMoneyId 财务用款管理主键
     * @return 结果
     */
    @Override
    public int deleteMoneyBySpendMoneyId(Integer spendMoneyId)
    {
        return moneyMapper.deleteMoneyBySpendMoneyId(spendMoneyId);
    }
}
